{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Example usage of align() method:\n",
    "generate two random sets of points and align them using\n",
    "the Iterative Closest Point algorithm.\"\"\"\n",
    "from random import uniform as u\n",
    "from vedo import *\n",
    "\n",
    "# embedWindow('panel')\n",
    "\n",
    "vp = Plotter(bg='w') # create the Plotter instance explicitly\n",
    "\n",
    "N1 = 15  # number of points of first set\n",
    "N2 = 15  # number of points of second set\n",
    "x = 1.0  # add some randomness\n",
    "\n",
    "pts1 = [(u(0, x),   u(0, x), u(0, x) +i) for i in range(N1)]\n",
    "pts2 = [(u(0, x)+3, u(0, x) + i/2. +2, u(0, x)+i+1) for i in range(N2)]\n",
    "\n",
    "vpts1 = Points(pts1, c=\"b\") # build 2 vertex-only meshes\n",
    "vpts2 = Points(pts2, c=\"r\")\n",
    "vp += [vpts1, vpts2]\n",
    "\n",
    "# find best alignment between the 2 sets of Points, e.i. find\n",
    "# how to move act1 to best match act2\n",
    "alpts1 = vpts1.alignTo(vpts2).points()\n",
    "\n",
    "for i in range(N1):  # draw arrows to see where points end up\n",
    "    vp += Arrow(pts1[i], alpts1[i], s=0.01, c=\"k\", alpha=0.2)\n",
    "\n",
    "vp += Points(alpts1, c=\"blue\")\n",
    "\n",
    "vp.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
